<?php
namespace app\modules\test\models;

use app\libs\Method;
use app\libs\Pager;
use yii\db\ActiveRecord;

class TestPublic extends ActiveRecord
{

    public static function tableName()
    {
        return '{{%test_public}}';
    }

    public static function getAvgTime($pubData)
    {
        $pub = TestPublic::find()->asArray()->where('cateId=' . $pubData['cateId'] . ' and subjectId="' . $pubData['subjectId'] . '"')->all();

        if ($pub['cateId']==21) {
            static $time = 0;
            foreach ($pub as $k => $v) {
                $val = json_decode($v['time'], true);
                foreach ($val as $value) {
                    $time += $value;
                }
            }
            $avgtime = floor(($time / count($pub) / 60)) . '分' . ($time / count($pub) % 60) . '秒';
            return $avgtime;
        }else{
            return '10分5秒';
        }
    }

}
